<%@ include file="/en/jsp/static.jsp" %>
<%@ taglib uri="/linuxbox/common.tld" prefix="common" %>
<%@ page import="java.util.*,linuxbox.reservation.logic.*,linuxbox.resource.logic.*" %>

<jsp:useBean id="cat" class="linuxbox.resource.logic.BoxResourceCat"/>

<%
  String SORTBY = (String) session.getAttribute("resource.SORTBY");
  if (SORTBY==null)
  {
    SORTBY = "name";
    session.setAttribute("resource.SORTBY", SORTBY);
  }

  boolean sortAsc = true;
  String tmp = (String) session.getAttribute("resource.ASC");
  if (tmp!=null && tmp.length() > 0)
    sortAsc = new Boolean(tmp).booleanValue();
  else
    session.setAttribute("resource.ASC", "true");

  int curPage = 0;
  String PAGE = (String) request.getParameter("PAGE");
  if (PAGE != null)
    curPage = Integer.parseInt(PAGE);

  BoxResource home = BoxResource.getInstance();
  int entriesPerPage = sec.getConfigInt("resource", "General", "Entries Per Page");
  int totalPage = home.getTotalPages(entriesPerPage);
  if (curPage >= totalPage)
    curPage = totalPage-1;

  String resourcePage = BoxStatic.jspDir+"resource/BoxResource.jsp";
  String resourceAction = BoxStatic.servletDir+"BoxResourceAction";
  Iterator it = home.getResources(SORTBY, sortAsc, entriesPerPage*curPage, entriesPerPage);
  int count = 0;
%>


<jsp:include page="/en/jsp/header.jsp" flush="true"/>

<FORM action="<%=BoxStatic.servletDir%>BoxResourceAction" method="POST">

<table width="100%" height=26 align=middle border=0 cellpadding=0 cellspacing=0 bgcolor="#f4f4f4" style="font-size:16px;color:#d05000">
  <tr>
    <td>
      &nbsp;<img src="<%=BoxStatic.imageDir%>itemball.jpg" width=14 height=15 border=0 align="absmiddle">
      <b><%=boxName%> - Resource</b>
    </td>
    <td align=right>
      <a href="<%=BoxStatic.jspDir%>resource/BoxResourceCat.jsp">
        Categories
      </a>&nbsp;|&nbsp;
      <a href="<%=BoxStatic.servletDir%>BoxResourceSettingsAction?SubmitEdit=edit">
        Settings
      </a>
    </td>
  </tr>
</table>

<hr width="100%" color=#E06000 align=left>

<table width="100%" border=0 cellpadding=0 cellspacing=0>
  <tr>
    <td>
      <table width="100%">
        <tr>
          <td>
      <% if (sec.isResourceAdmin())
          { %>
            <input type="submit" name="SubmitEdit" value="Add...">
      <%  } %>
          </td>
          <td align=right>
            <common:Page curPage="<%=curPage%>" totalPage="<%=totalPage%>" action="<%=resourcePage%>" />
          </td>
        </tr>
      </table>
    </td>
  </tr>
  <tr bgcolor=silver>
    <td>
      <TABLE WIDTH="100%" BORDER=0 CELLSPACING=1 CELLPADDING=0 bgColor=#dddddd>
<%
      if ( it != null && it.hasNext())
      {
        String[] headers = {"Name", "Category", "Location", "Reserve","Description","Allow People","Delete"};
        String[] sortby = {"name", "category", "location", "","","",""};
%>
        <tr bgcolor=#7EC1F3>
          <common:ListHeader headers="<%=headers%>" sortby="<%=sortby%>" curSortBy="<%=SORTBY%>" sortAsc="<%=!sortAsc%>" action="<%=resourceAction%>" />
        </tr>
        <common:Iteration name="entry" type="linuxbox.resource.logic.BoxResourceEntry" group="<%=it%>">
          <TR <% if ((count++ % 2) == 0) out.print("bgcolor=#f0f0f0"); %>>
            <TD><a href="<%=BoxStatic.servletDir%>BoxResourceAction?SubmitEdit=edit&ID=<%=entry.getID()%>"><%=entry.getName()%></a></TD>
            <TD><%=cat.getCategoryString(entry.getCategory())%></TD>
            <TD><%=entry.getLocation()%></TD>
            <TD align=center><a href="<%=BoxStatic.servletDir%>BoxReservationAction?SubmitEdit=Edit&RESOURCEID=<%=entry.getID()%>">Reserve</a> </TD>
            <TD><%=entry.getDescription()%></TD>
            <TD align=center><%=entry.getAllowPeople()%></TD>
            <TD align = center>
            <% if (sec.isResourceAdmin())
                { %>
              <a href="<%=BoxStatic.servletDir%>BoxResourceAction?SubmitDelete=del&ID=<%=entry.getID()%>">Delete</a>
            <%  }%>
            </TD>
          </TR>
        </common:Iteration>
<%
        }
        else
        {
          out.print("<TR><TD bgColor=#eeeeee align=center>You have no resources.</TD></TR>");
        }
%>
        </TABLE>
    </td>
  </tr>
  <%
    if (count > 0)
    {
  %>
  <tr>
    <td>
      <table width="100%">
        <tr>
          <td>
      <% if (sec.isResourceAdmin())
          { %>
            <input type="submit" name="SubmitEdit" value="Add...">
      <%  } %>
          </td>
          <td align=right>
            <common:Page curPage="<%=curPage%>" totalPage="<%=totalPage%>" action="<%=resourcePage%>" />
          </td>
        </tr>
      </table>
    </td>
  </tr>
<%    } %>

</table>
<hr width="100%" color=#E06000 align=left>

</FORM>

<jsp:include page="/en/jsp/footer.jsp" flush="true"/>
